package org.jeecg.modules.business.doc.outbound.controller;

import com.alibaba.fastjson.JSONObject;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.jeecg.common.api.vo.Result;
import org.jeecg.modules.business.doc.outbound.entity.WmsOutReceiptLoadCheck;
import org.jeecg.modules.business.doc.outbound.entity.vo.*;
import org.jeecg.modules.business.doc.outbound.service.IWmsOutReceiptLoadCheckService;
import org.jeecg.modules.business.outbound.entity.vo.OutboundTaskFullPickVO;
import org.springframework.web.bind.annotation.*;

import javax.validation.Valid;
import java.util.List;



/**
 * @Description: 出库单-装车复核
 * @Author: jeecg-boot
 * @Date: 2023-08-09
 * @Version: V1.0
 */
@Api(tags = "出库单-装车复核")
@RestController
@RequestMapping("/business/wmsOutReceipt/loadCheck")
@Slf4j
@RequiredArgsConstructor
public class WmsOutReceiptLoadCheckController {

    private final IWmsOutReceiptLoadCheckService wmsOutReceiptLoadCheckService;

    /**
     * 查询所有未复核信息
     *
     * @return
     */
    @ApiOperation(value = "查询所有未复核信息", notes = "查询所有未复核信息")
    @GetMapping(value = "/listAllUnCheck")
    public Result<IPage<OutboundReceiptLoadCheckFullVO>> listAllUnCheck(@RequestParam(value = "receiptId") String receiptId,
                                                                        @RequestParam(value = "materialName",required = false) String materialName,
                                                                        @RequestParam(value = "batchCode",required = false) String batchCode,
                                                                        @RequestParam(value = "carNumber",required = false) String carNumber,
                                                                        @RequestParam(name = "pageNo", defaultValue = "1") Integer pageNo,
                                                                        @RequestParam(name = "pageSize", defaultValue = "10") Integer pageSize
                                                                       ) {
        IPage<WmsOutReceiptLoadCheck> page=new Page<>(pageNo, pageSize);
        IPage<OutboundReceiptLoadCheckFullVO> pageList=wmsOutReceiptLoadCheckService.listAllUnCheck(page,receiptId,materialName,batchCode,carNumber);
        return Result.ok(pageList);
    }

    /**
     * 查询所有已复核信息
     *
     * @param receiptId 出库单id
     * @return
     */
    @ApiOperation(value = "查询所有已复核信息", notes = "查询所有已复核信息")
    @GetMapping(value = "/listAllChecked")
    public Result<IPage<OutboundReceiptLoadCheckVO>> listAllChecked(@RequestParam(value = "receiptId") String receiptId,
                                                                   @RequestParam(value = "materialName",required = false) String materialName,
                                                                   @RequestParam(value = "batchCode",required = false) String batchCode,
                                                                   @RequestParam(name = "pageNo", defaultValue = "1") Integer pageNo,
                                                                   @RequestParam(name = "pageSize", defaultValue = "10") Integer pageSize
    ) {
        IPage<WmsOutReceiptLoadCheck> page=new Page<>(pageNo, pageSize);
        IPage<OutboundReceiptLoadCheckVO> pageList=wmsOutReceiptLoadCheckService.listAllChecked(page,receiptId,materialName,batchCode);
        return Result.OK(pageList);
    }

    /**
     * 增加复核信息
     *
     * @param addLoadCheckVO
     * @return
     */
    @ApiOperation(value = "增加复核信息", notes = "增加复核信息")
    @PostMapping(value = "/addCheckInfo")
    public Result<Void> addCheckInfo(@Valid @RequestBody OutboundAddLoadCheckVO addLoadCheckVO) {
        wmsOutReceiptLoadCheckService.addCheckInfo(addLoadCheckVO);
        return Result.ok();
    }

    /**
     * 取消复核
     *
     * @param cancelLoadCheckVO
     * @return
     */
    @ApiOperation(value = "取消复核", notes = "取消复核")
    @PostMapping("cancelCheck")
    public Result<Void> cancelPick(@Valid @RequestBody OutboundCancelLoadCheckVO cancelLoadCheckVO) {
        wmsOutReceiptLoadCheckService.cancelPick(cancelLoadCheckVO);
        return Result.ok();
    }

    /**
     * 根据任务物料id取消复核
     *
     * @param cancelLoadCheckByIdVO
     * @return
     */
    @ApiOperation(value = "根据任务物料id取消复核", notes = "根据任务物料id取消复核")
    @PostMapping("cancelPickByTaskMaterialId")
    public Result<Void> cancelPickByTaskMaterialId(@Valid @RequestBody OutboundCancelLoadCheckByIdVO cancelLoadCheckByIdVO) {
        wmsOutReceiptLoadCheckService.cancelPickByTaskMaterialId(cancelLoadCheckByIdVO);
        return Result.ok();
    }

    /**
     * 复核出库(已废弃)
     * @return
     */
    @ApiOperation(value = "复核出库", notes = "复核出库")
    @PostMapping("checkOut")
    public Result<Void> checkOut(@RequestBody JSONObject jsonData){
        wmsOutReceiptLoadCheckService.checkOut(jsonData.getString("checkId"));
        return Result.ok();
    }

    /**
     * 装车复核时扫码查询待装车复核物料
     */
    @ApiOperation(value = "装车复核时扫码查询待装车复核物料", notes = "装车复核时扫码查询待装车复核物料")
    @GetMapping("/pda/getMaterialByNameAndTaskId")
    public Result<List<OutboundReceiptLoadCheckFullVO>> getLoadCheckByNameAndTaskId(@RequestParam("name") String name, @RequestParam("receiptId") String receiptId) {
        List<OutboundReceiptLoadCheckFullVO> list=wmsOutReceiptLoadCheckService.getLoadCheckByNameAndTaskId(name,receiptId);
        return Result.ok(list);
    }




}
